<!--

    Copyright © 2016-2025 The Thingsboard Authors

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<ng-container [formGroup]="windSpeedDirectionWidgetConfigForm">
  <tb-timewindow-config-panel *ngIf="displayTimewindowConfig"
                              [onlyHistoryTimewindow]="onlyHistoryTimewindow()"
                              formControlName="timewindowConfig">
  </tb-timewindow-config-panel>
  <tb-datasources
    [configMode]="basicMode"
    hideDataKeys
    hideDatasourceLabel
    formControlName="datasources">
  </tb-datasources>
  <div class="tb-form-panel">
    <div class="tb-form-panel-title" translate>widgets.wind-speed-direction.values</div>
    <div class="tb-form-row">
      <div class="fixed-title-width tb-required" translate>widgets.wind-speed-direction.wind-direction</div>
      <div class="flex flex-1 flex-row items-center justify-start gap-2">
        <tb-data-key-row class="flex-1"
                         formControlName="windDirectionKey"
                         required
                         [datasourceType]="datasource?.type"
                         [deviceId]="datasource?.deviceId"
                         [entityAliasId]="datasource?.entityAliasId"
                         hideDataKeyLabel
                         hideDataKeyColor
                         hideDataKeyDecimals
                         hideDataKeyUnits>
        </tb-data-key-row>
        <tb-font-settings *ngIf="!windSpeedDirectionWidgetConfigForm.get('centerValueKey').value"
                          formControlName="centerValueFont"
                          [autoScale]="true"
                          [initialPreviewStyle]="{ color: windSpeedDirectionWidgetConfigForm.get('centerValueColor').value?.color }"
                          [previewText]="centerValuePreviewFn">
        </tb-font-settings>
        <tb-color-settings *ngIf="!windSpeedDirectionWidgetConfigForm.get('centerValueKey').value"
                           formControlName="centerValueColor" settingsKey="{{'widgets.wind-speed-direction.wind-direction' | translate }}">
        </tb-color-settings>
      </div>
    </div>
    <div class="tb-form-row column-xs">
      <div class="fixed-title-width" translate>widgets.wind-speed-direction.center-value</div>
      <div class="flex flex-1 flex-row items-center justify-start gap-2">
        <tb-data-key-row class="flex-1"
                         formControlName="centerValueKey"
                         [datasourceType]="datasource?.type"
                         [deviceId]="datasource?.deviceId"
                         [entityAliasId]="datasource?.entityAliasId"
                         hideDataKeyLabel
                         hideDataKeyColor>
        </tb-data-key-row>
        <tb-font-settings *ngIf="windSpeedDirectionWidgetConfigForm.get('centerValueKey').value"
                          formControlName="centerValueFont"
                          [autoScale]="true"
                          [initialPreviewStyle]="{ color: windSpeedDirectionWidgetConfigForm.get('centerValueColor').value?.color }"
                          [previewText]="centerValuePreviewFn">
        </tb-font-settings>
        <tb-color-settings *ngIf="windSpeedDirectionWidgetConfigForm.get('centerValueKey').value"
                           formControlName="centerValueColor" settingsKey="{{'widgets.wind-speed-direction.center-value' | translate }}">
        </tb-color-settings>
      </div>
    </div>
  </div>
  <div class="tb-form-panel">
    <div class="tb-form-panel-title" translate>widget-config.appearance</div>
    <tb-image-cards-select rowHeight="1:1"
                           [cols]="{columns: 3,
                                    breakpoints: {
                                      'lt-md': 2
                                    }}"
                           label="{{ 'widgets.wind-speed-direction.layout' | translate }}" formControlName="layout">
      <tb-image-cards-select-option *ngFor="let layout of windSpeedDirectionLayouts"
                                    [value]="layout"
                                    [image]="windSpeedDirectionLayoutImageMap.get(layout)">
        {{ windSpeedDirectionLayoutTranslationMap.get(layout) | translate }}
      </tb-image-cards-select-option>
    </tb-image-cards-select>
    <div class="tb-form-row column-xs">
      <mat-slide-toggle class="mat-slide fixed-title-width" formControlName="showTitle">
        {{ 'widget-config.title' | translate }}
      </mat-slide-toggle>
      <div class="flex flex-1 flex-row items-center justify-start gap-2">
        <mat-form-field class="flex" appearance="outline" subscriptSizing="dynamic">
          <input matInput formControlName="title" placeholder="{{ 'widget-config.set' | translate }}">
        </mat-form-field>
        <tb-font-settings formControlName="titleFont"
                          clearButton
                          [previewText]="windSpeedDirectionWidgetConfigForm.get('title').value"
                          [initialPreviewStyle]="widgetConfig.config.titleStyle">
        </tb-font-settings>
        <tb-color-input asBoxInput
                        colorClearButton
                        formControlName="titleColor">
        </tb-color-input>
      </div>
    </div>
    <div class="tb-form-row column-xs">
      <mat-slide-toggle class="mat-slide fixed-title-width" formControlName="showIcon">
        {{ 'widgets.wind-speed-direction.icon' | translate }}
      </mat-slide-toggle>
      <div class="flex flex-1 flex-row items-center justify-start gap-2">
        <mat-form-field appearance="outline" class="number flex" subscriptSizing="dynamic">
          <input matInput type="number" min="0" formControlName="iconSize" placeholder="{{ 'widget-config.set' | translate }}">
        </mat-form-field>
        <tb-css-unit-select class="flex-1" formControlName="iconSizeUnit"></tb-css-unit-select>
        <tb-material-icon-select asBoxInput
                                 iconClearButton
                                 [color]="windSpeedDirectionWidgetConfigForm.get('iconColor').value"
                                 formControlName="icon">
        </tb-material-icon-select>
        <tb-color-input asBoxInput
                        colorClearButton
                        formControlName="iconColor">
        </tb-color-input>
      </div>
    </div>
  </div>
  <div class="tb-form-panel">
    <div class="tb-form-panel-title" translate>widgets.wind-speed-direction.ticks</div>
    <div class="tb-form-row space-between">
      <div>{{ 'widget-config.color' | translate }}</div>
      <tb-color-input asBoxInput
                      formControlName="ticksColor">
      </tb-color-input>
    </div>
    <div class="tb-form-row space-between">
      <div>{{ 'widgets.wind-speed-direction.labels-type' | translate }}</div>
      <mat-form-field class="medium-width" appearance="outline" subscriptSizing="dynamic">
        <mat-select formControlName="directionalNamesElseDegrees">
          <mat-option [value]="true">
            {{ 'widgets.wind-speed-direction.directional-names' | translate }}
          </mat-option>
          <mat-option [value]="false">
            {{ 'widgets.wind-speed-direction.degrees' | translate }}
          </mat-option>
        </mat-select>
      </mat-form-field>
    </div>
    <div class="tb-form-row space-between">
      <div>{{ 'widgets.wind-speed-direction.major-ticks' | translate }}</div>
      <div class="flex flex-row items-center justify-start gap-2">
        <tb-font-settings [class.!hidden]="!majorTicksFontEnabled"
                          formControlName="majorTicksFont"
                          [initialPreviewStyle]="{ color: windSpeedDirectionWidgetConfigForm.get('majorTicksColor').value }"
                          [autoScale]="true"
                          previewText="N E S W">
        </tb-font-settings>
        <tb-color-input asBoxInput
                        formControlName="majorTicksColor">
        </tb-color-input>
      </div>
    </div>
    <div class="tb-form-row space-between">
      <div>{{ 'widgets.wind-speed-direction.minor-ticks' | translate }}</div>
      <div class="flex flex-row items-center justify-start gap-2">
        <tb-font-settings [class.!hidden]="!minorTicksFontEnabled"
                          formControlName="minorTicksFont"
                          [initialPreviewStyle]="{ color: windSpeedDirectionWidgetConfigForm.get('minorTicksColor').value }"
                          [autoScale]="true"
                          previewText="NE SE SW NW">
        </tb-font-settings>
        <tb-color-input asBoxInput
                        formControlName="minorTicksColor">
        </tb-color-input>
      </div>
    </div>
  </div>
  <div class="tb-form-panel">
    <div class="tb-form-panel-title" translate>widgets.wind-speed-direction.arrow</div>
    <div class="tb-form-row space-between">
      <div>{{ 'widget-config.color' | translate }}</div>
      <tb-color-input asBoxInput
                      formControlName="arrowColor">
      </tb-color-input>
    </div>
  </div>
  <div class="tb-form-panel">
    <div class="tb-form-panel-title" translate>widget-config.card-appearance</div>
    <div class="tb-form-row space-between">
      <div>{{ 'widgets.background.background' | translate }}</div>
      <tb-background-settings formControlName="background">
      </tb-background-settings>
    </div>
    <div class="tb-form-row space-between column-lt-md">
      <div translate>widget-config.show-card-buttons</div>
      <mat-chip-listbox multiple formControlName="cardButtons">
        <mat-chip-option value="fullscreen">{{ 'fullscreen.fullscreen' | translate }}</mat-chip-option>
      </mat-chip-listbox>
    </div>
    <div class="tb-form-row space-between">
      <div>{{ 'widget-config.card-border-radius' | translate }}</div>
      <mat-form-field appearance="outline" subscriptSizing="dynamic">
        <input matInput formControlName="borderRadius" placeholder="{{ 'widget-config.set' | translate }}">
      </mat-form-field>
    </div>
    <div class="tb-form-row space-between">
      <div>{{ 'widget-config.card-padding' | translate }}</div>
      <mat-form-field appearance="outline" subscriptSizing="dynamic">
        <input matInput formControlName="padding" placeholder="{{ 'widget-config.set' | translate }}">
      </mat-form-field>
    </div>
  </div>
  <tb-widget-actions-panel
    formControlName="actions">
  </tb-widget-actions-panel>
</ng-container>
